import { getProcessSelect, getWorkflowSelect } from '@/api/salesleads/salesmanagement/business'

import { reactive } from 'vue'
let workflow_id: any = ''
const stageOptionList = reactive<Array<any>>([])
export const searchOption = [
  {
    label: '商机名称',
    name: 'name',
    value: '',
    type: 'input',
    placeholder: '请输入商机编号 | 名称'
  },
  {
    label: '商机流程',
    name: 'workflow_id',
    value: '',
    placeholder: '请选择商机流程',
    type: 'select',
    fetchOptionApi: async () => {
      return await getWorkflowSelect({ state: 'all' })
    },
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    }),
    async change(val: any, from: any) {
      workflow_id = val
      from.stage_id = ''
      if (!workflow_id) {
        stageOptionList.splice(0, stageOptionList.length)
        return
      }
      const data: any = await getProcessSelect({ workflow_id })
      stageOptionList.splice(0, stageOptionList.length, ...data)
    }
  },
  {
    label: '商机阶段',
    name: 'stage_id',
    value: '',
    placeholder: '请选择商机阶段',
    type: 'select',
    optionList: stageOptionList,
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    })
  },
  {
    label: '创建时间',
    name: 'created_at',
    value: '',
    type: 'datePicker',
    datePickerType: 'daterange',
    datePickerFormat: 'YYYY-MM-DD HH:mm:ss',
    valueFormat: 'YYYY-MM-DD HH:mm:ss',
    startPlaceholder: '开始日期',
    endPlaceholder: '结束日期'
  },
  {
    label: '提审时间',
    name: 'audit_created_at',
    value: '',
    type: 'datePicker',
    datePickerType: 'daterange',
    datePickerFormat: 'YYYY-MM-DD HH:mm:ss',
    valueFormat: 'YYYY-MM-DD HH:mm:ss',
    placeholder: '请选择提审时间',
  },
  {
    label: '审核时间',
    name: 'audit_time',
    value: '',
    type: 'datePicker',
    datePickerType: 'date',
    valueFormat: 'YYYY-MM-DD',
    defaultTime: new Date(),
    placeholder: '请选择审核时间',
  },

  {
    label: '预计赢单时间',
    name: 'predict_time',
    value: '',
    type: 'datePicker',
    datePickerType: 'date',
    valueFormat: 'YYYY-MM-DD',
    defaultTime: new Date(),
    placeholder: '选择日期'
  },
  {
    label: '赢单时间',
    name: 'actual_time',
    value: '',
    type: 'datePicker',
    datePickerType: 'date',
    valueFormat: 'YYYY-MM-DD',
    defaultTime: new Date(),
    placeholder: '选择日期'
  },
  {
    label: '客户名称',
    name: 'cust_info',
    value: '',
    type: 'input',
    placeholder: '请输入客户名称|手机号搜索'
  },
  {
    label: '归属员工',
    name: 'belong_uid',
    value: '',
    type: 'select',
    isUserSelect: true,
    isMember: true,
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    }),
    popperClass: 'zw-hide_select_option',
    // multiple: true,
    placeholder: '请选择归属员工'
  },
  {
    label: '协助员工',
    name: 'assist_ids',
    value: '',
    type: 'select',
    placeholder: '请选择员工',
    multiple: true,
    isUserSelect: true,
    isMember: true,
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    }),
    popperClass: 'zw-hide_select_option',
  },
  {
    label: '提审员工',
    name: 'audit_created_uid',
    value: '',
    type: 'select',
    placeholder: '请选择员工',
    isUserSelect: true,
    isMember: true,
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    }),
    popperClass: 'zw-hide_select_option',
  },
  {
    label: '审核员工',
    name: 'audit_uid',
    value: '',
    type: 'select',
    placeholder: '请选择员工',
    isUserSelect: true,
    isMember: true,
    formatOption: (v: any) => ({
      label: v.name,
      value: v.id
    }),
    popperClass: 'zw-hide_select_option',
  },
  {
    label: '商机金额',
    name: 'amount',
    value: '',
    type: 'section',
    isForbidNegativeNumber: true,
    placeholderBefore: '请输入金额',
    placeholderAfter: '请输入金额'
  },
]